<template>
  <div id="teacher-management" class="container">
    <table-filter>
      <el-input
        placeholder="请输入机构名称"
        clearable
        v-model="apiSetting.data.orgaName"
        class="input-with-select"
      >
      </el-input>
      <el-input
              placeholder="请输入教师账号"
              clearable
              v-model="apiSetting.data.teaCode"
              class="input-with-select"
      ></el-input>
      <el-input
              placeholder="请输入教师名称"
              clearable
              v-model="apiSetting.data.teaName"
              class="input-with-select"
      ></el-input>
      <el-button plain type="warning" @click="search">搜索</el-button>
    </table-filter>
    <el-row>
      <el-button plain type="primary" @click="showEaDialog = true"
        >添加教师</el-button
      >
      <el-button
        @click="
          techIds !== '' && delRow(`/sys/teacher/deleteUser/${techIds}`, '教师')
        "
        plain
        type="danger"
        >删除教师</el-button
      >
        <el-button plain type="primary" @click="exportTea()">导出教师</el-button>
    </el-row>
    <data-table
      ref="dtb"
      :api-setting="apiSetting"
      pagination
      :sort-column="sortColumn"
      @selection-change="selectTeacher"
    >
      <el-table-column type="selection" width="39"> </el-table-column>
      <!--<el-table-column
        fixed
        prop="userid"
        label="UserID"
        width="120"
        sortable
      />-->
      <el-table-column prop="usercode" label="帐号" width="230" />
      <el-table-column prop="username" label="姓名" width="350" sortable />
      <el-table-column prop="school" label="学校" width="350" />
      <el-table-column
        prop="clazzs"
        label="管理机构"
        width="340"
        show-overflow-tooltip
      />
      <el-table-column label="状态" width="150">
        <template slot-scope="{ row }">
          <el-switch
            v-model="row.isenable"
            :active-value="true"
            :inactive-value="false"
            @change="setUserStatus($event, row)"
            active-text="启用"
            inactive-text="禁用"
          >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作">
        <template slot-scope="{ row }">
          <el-button class="warning" @click="edit(row)" type="text" size="small"
            >编辑
          </el-button>
          <el-button type="text" size="small" @click="reset(row)"
            >重置密码</el-button
          >
          <el-button
            type="text"
            size="small"
            class="danger"
            @click="delRow(`/sys/teacher/deleteUser/${row.userid}`, '教师')"
            >删除
          </el-button>
        </template>
      </el-table-column>
    </data-table>
    <ea-user
      ref="eaDialog"
      module-name="教师"
      upload-api="/api/sys/teacher/avatarUpload"
      submit-api="/sys/teacher/addOrUpdate"
      :show.sync="showEaDialog"
      @on-reload="dtb.loadData()"
    />
  </div>
</template>

<script>
import eaDialog from "@/mixins/refs/eaDialog";
import dtb from "@/mixins/refs/dtb";
import deleteRow from "@/mixins/dataTable/deleteRow";
import EaUser from "@/views/component/EaUser";
import user from "@/mixins/business/user";
import tbSearch from "@/mixins/dataTable/tbSearch";

export default {
  name: "index",
  components: { EaUser },
  mixins: [tbSearch, user, deleteRow, eaDialog, dtb],
  data() {
    return {
      sortColumn: ["userid", "username"],
      apiSetting: {
        method: "post",
        url: "/sys/teacher/getTeaList",
        data: {
          orgaName: "",
          teaName: "",
          teaCode: ""
        }
      },
      apis: {
        resetPwd: "/sys/teacher/resetPwd",
        setUserStatus: "/sys/teacher/enableUser",
        userDetail: "/sys/teacher/getTeacherDetail"
      },
      techIds: ""
    };
  },
  methods: {
    selectTeacher(v) {
      this.techIds = v.map(item => item.userid).join(",");
    },
    //导出教师
    exportTea(){
      const { orgaName, teaCode, teaName } = this.apiSetting.data;
      this.downLoadFile(
              {
                method: "post",
                url: "/sys/teacher/exportStuExcel",   
                data: {
                  cols: [
                    "usercode",
                    "username",
                    "school",
                    "clazzs",
                    "depts"
                  ],
                  orgaName,
                  teaCode,
                  teaName
                }
              },
              "教师记录.xls"
      );
    }
  }
};
</script>

<style scoped></style>
